package servlet;

import model.Cart;
import service.CartService;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AddCart_Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        String bkName = req.getParameter("bkName");
        String bkPrice = req.getParameter("bkPrice");
        System.out.println(bkName);
        CartService service = new CartService();
        Cart cart = new Cart("1","1","0", bkName);
        System.out.println(service.AddCart(cart, bkName));
        req.setAttribute("bkName",bkName);
        req.setAttribute("bkPrice",bkPrice);
        req.getRequestDispatcher("webpage/DetailPage.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
